@extends('admin.layouts.wap')
@section('title', '添加渠道二维码')

@section('content')

<meta name="csrf-token" content="{{ csrf_token() }}">
<input type="hidden" id="appid" value="{{ $minapps->appid }}">

<div class="row">
    <div class="col-md-12">
        @if($minapps->status == 2)
        <form id="comment-form" method="GET" action="{{ url('/admin/miniapps/fast_register_betaweapp_event',['appid'=>$minapps->appid]) }}">
        @elseif($minapps->status == 3)
        <form id="comment-form" method="POST" action="{{ url('/admin/miniapps/verify_beta_weapp',['appid'=>$minapps->appid]) }}">
        @elseif($minapps->status == 5 || $minapps->status == 1)
        <form id="comment-form" method="POST" action="{{ url('/admin/miniapps/wxa_commit',['appid'=>$minapps->appid]) }}">
        @elseif($minapps->status == 7)
        <form id="comment-form" method="GET" action="{{ url('/admin/miniapps/wxa_recommit',['appid'=>$minapps->appid]) }}">
        @elseif($minapps->status == 8)
        <form id="comment-form" method="GET" action="{{ url('/admin/miniapps/wxa_release',['appid'=>$minapps->appid]) }}">
        @else
        <form id="comment-form" method="GET" action="{{ URL::current() }}">
        @endif
            <div class="card">
                <div class="card-header">
                    <div class="card-title">小程序状态更新</div>
                </div>
                <div class="card-body">
                    @if($minapps->status == 2)
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                    <div class="form-group col-md-6">
                        <label for="text">请使用微信<font class="text-primary"> {{ Auth::user()->nickname }} </font>扫描下方二维码,绑定<font class="text-primary">小程序管理员</font>：</label><br>
                        {!! QrCode::size(150)->generate($minappslistsinfo->authorize_url); !!}
                    </div>
                    @elseif($minapps->status == 3)
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">企业名称：</label>
                        <input type="text" class="form-control" name="enterprise_name" value="{{ old('enterprise_name') }}" placeholder="请输入企业名称">
                    </div>
                    <div class="form-group col-md-12">
                        <label for="text">企业代码类型：</label><br>
                        <label class="form-radio-label">
                            <input class="form-radio-input" type="radio" id="code_type" name="code_type" value="1" checked="">
                            <span class="form-radio-sign">统一社会信用代码</span>
                        </label>
                        <label class="form-radio-label ml-3">
                            <input class="form-radio-input" type="radio" id="code_type" name="code_type" value="2">
                            <span class="form-radio-sign">组织机构代码</span>
                        </label>
                        <label class="form-radio-label ml-3">
                            <input class="form-radio-input" type="radio" id="code_type" name="code_type" value="3">
                            <span class="form-radio-sign">营业执照注册号</span>
                        </label>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">企业代码：</label>
                        <input type="text" class="form-control" name="code" value="{{ old('code') }}" placeholder="请输入企业代码">
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">法人微信号：</label>
                        <input type="text" class="form-control" name="legal_persona_wechat" value="{{ old('legal_persona_wechat') }}" placeholder="请输入法人微信号">
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">法人姓名：</label>
                        <input type="text" class="form-control" name="legal_persona_name" value="{{ old('legal_persona_name') }}" placeholder="请输入法人姓名">
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">法人身份证号：</label>
                        <input type="text" class="form-control" name="legal_persona_idcard" value="{{ old('legal_persona_idcard') }}" placeholder="请输入法人身份证号">
                    </div>
                    @elseif($minapps->status == 4)
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                    <div class="form-group col-md-12">
                        @if($minapps->status_code == 89251)
                        <label for="text">模板消息已下发，待法人人脸核身校验</label>
                        @elseif($minapps->status_code == 100001)
                        <label for="text">已下发的模板消息法人并未确认且已超时（24h），未进行身份证校验</label>
                        @elseif($minapps->status_code == 100002)
                        <label for="text">已下发的模板消息法人并未确认且已超时（24h），未进行人脸识别校验</label>
                        @elseif($minapps->status_code == 100003)
                        <label for="text">已下发的模板消息法人并未确认且已超时（24h）</label>
                        @elseif($minapps->status_code == 100004)
                        <label for="text">实名认证的信息和法人姓名不一致</label>
                        @elseif($minapps->status_code == 101)
                        <label for="text">法人扫脸后，工商数据返回：“企业已注销”</label>
                        @elseif($minapps->status_code == 102)
                        <label for="text">法人扫脸后，工商数据返回：“企业不存在或企业信息未更新”</label>
                        @elseif($minapps->status_code == 103)
                        <label for="text">法人扫脸后，工商数据返回：“企业法定代表人姓名不一致”</label>
                        @elseif($minapps->status_code == 104)
                        <label for="text">法人扫脸后，工商数据返回：“企业法定代表人身份证号码不一致”</label>
                        @elseif($minapps->status_code == 105)
                        <label for="text">法人扫脸后，法定代表人身份证号码，工商数据未更新，请 5-15 个工作日之后尝试</label>
                        @elseif($minapps->status_code == 1000)
                        <label for="text">法人扫脸后，工商数据返回：“企业信息或法定代表人信息不一致”</label>
                        @elseif($minapps->status_code == 89252)
                        <label for="text">模板消息已下发，待小程序管理员确认</label>
                        @else
                        <label for="text">小程序管理员确认转正超时或失败</label>
                        @endif
                    </div>
                    @elseif($minapps->status == 5)
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">小程序模版：</label><br>
                        <select class="form-control input-square" name="template_id">
                            @foreach($templates as $template)
                            <option value="{{ $template->template_id }}">{{ empty($template->source_miniprogram) ? "未命名": $template->source_miniprogram }} {{ $template->user_version }}</option>
                            @endforeach
                        </select>
                    </div>
                    @elseif($minapps->status == 6 || $minapps->status == 7)
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                        @if($auditStatus["status"] == 2)
                        <div class="form-group col-md-12">
                            <label for="text">小程序已提交微信审核,审核通过点击发布即可！</label>
                        </div>
                        @elseif($auditStatus["status"] == 0)
                        <div class="form-group col-md-12">
                            <label for="text">审核已通过,点击发布！</label>
                        </div>
                        @elseif($auditStatus["status"] == 1)
                        <div class="form-group col-md-12">
                            <label for="text">审核被拒绝！</label>
                            <label class="text-danger">{{ $auditStatus["reason"] }}</label>
                        </div>
                        @else
                        <div class="form-group col-md-12">
                            <label for="text">已撤回审核！</label>
                        </div>
                        @endif
                    @elseif($minapps->status == 8)
                    <div class="form-group col-md-12">
                        <label for="text">小程序已审核成功,点击下方按钮发布小程序！</label>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="text">小程序名称：</label>
                        <input type="text" class="form-control" name="name" value="{{ $minapps->name }}" disabled="disabled">
                        @csrf
                    </div>
                    @elseif($minapps->status == 1)
                    <div class="form-group col-md-3">
                        <label for="text">小程序模版：</label><br>
                        <select class="form-control input-square" name="template_id">
                            @foreach($templates as $template)
                            <option value="{{ $template->template_id }}">{{ empty($template->source_miniprogram) ? "未命名": $template->source_miniprogram }} {{ $template->user_version }}</option>
                            @endforeach
                        </select>
                        @csrf
                    </div>
                    @endif
                </div>
                <div class="card-action">
                    @if($minapps->status == 2)
                    <button class="btn btn-primary" type="submit">我已授权管理员</button>
                    @elseif($minapps->status == 3)
                    <button class="btn btn-primary" type="submit">前往认证</button>
                    @elseif($minapps->status == 4)
                    <button class="btn btn-primary" type="submit">已完成企业认证</button>
                    @elseif($minapps->status == 5 || $minapps->status == 1)
                    <button class="btn btn-primary" type="submit">提交代码审核</button>
                    @elseif($minapps->status == 6)
                    <div class="btn btn-default">小程序审核中...</div>
                    <a class="btn btn-danger" href="{{ url('/admin/miniapps/weapp_status_cancel',['appid'=>$minapps->appid]) }}">取消审核</a>
                    @elseif($minapps->status == 7)
                    <button class="btn btn-primary" type="submit">前往修改并重新提交</button>
                    @elseif($minapps->status == 8)
                    <button class="btn btn-success" type="submit">立即发布小程序</button>
                    @endif
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    function localUploadImage(id,maxsize) {
        var appid = $("#appid").val();
        var file = $("#"+id)[0];
        var medias_images_src = getObjectURL(file.files[0]) ; 
        $("#medias_images_show").attr("src",medias_images_src).show();
        var size = file.size;
        if (size > maxsize*1000) {
            alert("图片不能大于"+maxsize+"KB。");
            return;
        }
        var formData = new FormData();
        formData.append('media', file.files[0]);  //添加图片信息的参数
        formData.append('appid', appid);
        var _token = $('meta[name="csrf-token"]').attr('content');
        $.ajax({
            url: "/admin/upload/upload_miniapp_media",
            headers: {
                'X-CSRF-TOKEN': _token
            },
            type: "POST",
            dataType: "json",
            cache: false,
            data: formData,
            processData: false,// 不处理数据
            contentType: false, // 不设置内容类型
            success: function (result) {
                if (result.status == "success") {
                    $("#media_id").val(result.media_id);
                    mui.toast(result.msg);
                } else {
                    mui.toast(result.msg);
                }
            }
        })
    }

    function getObjectURL(file) {
        var url = null ;
        if (window.createObjectURL!=undefined) { // basic
            url = window.createObjectURL(file) ;
        } else if (window.URL!=undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file) ;
        } else if (window.webkitURL!=undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file) ;
        }
        return url ;
    }
</script>

@endsection
